use axum::{http::StatusCode, Json};
use serde::{Deserialize, Serialize};
use tracing::info;

#[derive(Debug, Serialize, Deserialize)]
pub struct HealthResponse {
    pub status: String,
    pub message: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ProxyRequest {
    pub url: String,
    pub method: String,
    pub headers: Option<std::collections::HashMap<String, String>>,
    pub body: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ProxyResponse {
    pub status: u16,
    pub headers: std::collections::HashMap<String, String>,
    pub body: String,
}

// 健康检查端点
pub async fn health_check() -> (StatusCode, Json<HealthResponse>) {
    info!("健康检查被调用");
    (
        StatusCode::OK,
        Json(HealthResponse {
            status: "ok".to_string(),
            message: "服务运行正常".to_string(),
        }),
    )
}

// HTTP代理端点
pub async fn proxy_http(
    Json(payload): Json<ProxyRequest>,
) -> Result<Json<ProxyResponse>, (StatusCode, String)> {
    info!("代理请求: {:?}", payload);
    
    // 这里实现实际的HTTP代理逻辑
    // 暂时返回一个模拟响应
    let response = ProxyResponse {
        status: 200,
        headers: std::collections::HashMap::new(),
        body: "代理请求已接收".to_string(),
    };
    
    Ok(Json(response))
}